<?php
function get_latest_article($num=10){
	global $_G;
	if(ican('view_hidden_category')) {
		$status = '1';
	}else{
		$status = 'c.status=0';
	}
	$sql = "SELECT a.*,c.catename FROM ".DB_PREFIX."article a LEFT JOIN ".DB_PREFIX."category c ON a.cid=c.cid WHERE c.type=0 AND $status AND a.ischeck=1 AND a.dateline < ".$_G['timestamp']." ORDER BY a.aid DESC LIMIT ".$num;
	$a =  $_G['db']->fetch_all($sql);
	return $a;
}
function get_hot_article($num=10){
	global $_G;
	if(ican('view_hidden_category')) {
		$status = '1';
	}else{
		$status = 'c.status=0';
	}
	$sql = "SELECT a.*,c.catename FROM ".DB_PREFIX."article a LEFT JOIN ".DB_PREFIX."category c ON a.cid=c.cid WHERE c.type=0 AND $status AND a.ischeck=1 AND a.dateline < ".$_G['timestamp']." ORDER BY a.views DESC LIMIT ".$num;
	$a =  $_G['db']->fetch_all($sql);
	return $a;
}
function get_latest_comment($num=10){
	global $_G;
	$query = $_G['db']->query("SELECT c.cid,c.username,c.content,c.referid,a.title FROM ".table('comment')."c LEFT JOIN".table('article')."a ON a.aid=c.referid WHERE c.type=0 AND c.status=1 ORDER BY c.cid DESC limit ".intval($num));
	while($row = $_G['db']->fetch_array($query)) {
		$comments[$row['cid']] = $row;
	}
	return 	$comments;	
}
function get_index_content($num=14){
	global $_G;
	if(intval($num)<10)$num =14;
	if(ican('view_hidden_category')) {
		$status = '1';
	}else{
		$status = 'c.status=0';
	}
	$sql = "SELECT a.default_image,a.title,a.summary,a.dateline,a.aid,a.comments,c.catename,a.views FROM ".DB_PREFIX."article a LEFT JOIN ".DB_PREFIX."category c ON a.cid=c.cid WHERE c.type=0 AND $status AND a.ischeck=1 AND a.dateline < ".$_G['timestamp']." ORDER BY a.aid DESC " ;
	$query = $_G['db']->page_query($sql,$num);
	$total = $_G['db']->result("SELECT COUNT(*) FROM ".DB_PREFIX."article a LEFT JOIN ".DB_PREFIX."category c ON a.cid=c.cid WHERE c.type=0 AND $status AND a.ischeck=1 AND a.dateline < ".$_G['timestamp']." ORDER BY a.aid DESC");
	while($data = $_G['db']->fetch_array($query)) {
		$return['content'][] = $data ;
	}
	$return['pager'] = pager($total,$num);
	return $return ;
}
function get_index_link($num=18){
	global $_G;
	return  $_G['db']->fetch_all("SELECT title,url,summary FROM".table('link')."WHERE visible=1 ORDER BY listorder ASC LIMIT ".intval($num));
}
function get_index_ads(){
	return '';
}